package com.yunxun.coinmessage.service;

import com.yunxun.coinmessage.dao.ExchangeDao;
import com.yunxun.coinmessage.dao.MesSourceDao;
import com.yunxun.coinmessage.entity.Exchange;
import com.yunxun.coinmessage.templatedata.MsgResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
/**
 * 交易所业务逻辑处理
 */
public class ExchangeService {
    @Autowired
    ExchangeDao exchangeDao;
   @Autowired
    MesSourceDao mesSourceDao;
    MsgResult msgResult;

    public MsgResult addExchange(Exchange exchange){
         int tag;
         List<Exchange> exchangeList=exchangeDao.queryByName(exchange.getEname());
         if(exchangeList.size()!=0){
             msgResult=new MsgResult(false,"该交易所已存在，请勿重复添加");
             return  msgResult;
         }
           tag= exchangeDao.addExchange(exchange);
            if(tag>0){
                msgResult=new MsgResult(true,"添加成功");
                return  msgResult;
            }else {
                msgResult=new MsgResult(false,"添加失败,请稍后重试");
                return  msgResult;
            }
    }
    public Exchange queryById(Integer eid)
    {
        return exchangeDao.queryById(eid);
    }
    public MsgResult deleteById(Integer eid){
            int tag;
            tag =exchangeDao.deleteById(eid);
            if(tag>0){
                msgResult=new MsgResult(true,"删除成功");
                return msgResult;
            }else{
                msgResult=new MsgResult(false,"删除失败，请稍后尝试");
                return msgResult;
            }



    }

    /**
     * 仅仅是更新交易所
     * @param exchange
     * @return
     */
    public MsgResult updateById(Exchange exchange){
          int tag;
            tag=exchangeDao.updateById(exchange);
            if(tag>0){
                msgResult=new MsgResult(true,"更新成功");
                return msgResult;
            }else{
                msgResult=new MsgResult(true,"更新失败");
                return msgResult;
            }


    }
    public List<Exchange> queryAll(){

        return exchangeDao.queryAll();
    }
    public List<Exchange> queryByPage(int start,int limit){
        return exchangeDao.queryByPage(start,limit);
    }

    public Integer queryTotal(){
      return   exchangeDao.queryTotal();
    }

}
